import Router from 'koa-router';

const config = require('./../config');

const router = new Router();

router.use('/*', async (ctx, next) => {
  let ip = ctx.request.ip.match(/\d+.\d+.\d+.\d+/);
  ctx.__ip = ip[0];

  // const url = ctx.request.url.toUpperCase();
  // const loginUrl = config.apiRoot + '/login';

  // if (ctx.session.account||
  //     (url===loginUrl.toUpperCase() && ctx.req.method.toUpperCase() === 'POST')) {
  //   await next();
  // } else {
  //   ctx.status = 401;
  //   ctx.body = { code: 10001, msg: '没有登录或登录已经过期', data: {} };
  // }
  next();
});

export default router;